//
//  UIButton+Extension.swift
//  波波微博
//
//  Created by wave on 15/8/2.
//  Copyright © 2015年 wave. All rights reserved.
//

import UIKit

extension UIButton{

    convenience init(title:String,imageName:String,fontSize:CGFloat = 12,color:UIColor = UIColor.darkGrayColor()){
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
    convenience init(title:String,color:UIColor,fontSize:CGFloat){
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
    convenience init(imageName:String){
        self.init()
        
        setImage(imageName)
    }
    
    func setImage(imageName: String){
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        //如果高亮图片不存在,不会设置
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    }
}